import math


def vector(point_a, point_b):
    return point_b[0] - point_a[0], point_b[1] - point_a[1]


def inner_product(vector_a, vector_b):
    return vector_a[0] * vector_b[0] + vector_a[1] * vector_b[1]


def cross_product(vector_a, vector_b):
    return vector_a[0] * vector_b[1] - vector_a[1] * vector_b[0]


def norm(vec):
    return math.sqrt(vec[0] * vec[0] + vec[1] * vec[1])


def cosine(vector_a, vector_b):
    return inner_product(vector_a, vector_b) / (norm(vector_a) * norm(vector_b))


def counterclockwise(triangle):
    """
    得到三角形三个点的逆时针排列

    :return: 三角形三个点的逆时针排列
    """
    a, b, c = triangle
    if cross_product(vector(a, b), vector(a, c)) < 0:
        a, b, c = a, c, b
    return a, b, c


def inside_triangle(triangle, p):
    a, b, c = counterclockwise(triangle)
    return cross_product(vector(a, b), vector(a, p)) > 0 \
        and cross_product(vector(b, c), vector(b, p)) > 0 \
        and cross_product(vector(c, a), vector(c, p)) > 0


def angle(vector_a, vector_b):
    """
    angle of two vector, range is [0, 2pi)

    :param vector_a:
    :param vector_b:
    :return:
    """
    theta = math.atan2(vector_b[1], vector_b[0]) - math.atan2(vector_a[1], vector_a[0])
    if theta < 0.0:
        return theta + 2 * math.pi
    return theta
    # if theta > math.pi:
    #     return theta - 2 * math.pi
    # elif theta <= -math.pi:
    #     return theta + 2 * math.pi
    # return theta


if __name__ == '__main__':
    print(angle((0, -1), (0, 0)))
